package {{ configuration.basePackage }}.controller.{{ configuration.module }};


import com.example.studyllm.dto.validate.Add;
import com.example.studyllm.dto.validate.Update;
import com.example.studyllm.entity.{{ configuration.module }}.{{ configuration.javaName }};
import com.example.studyllm.service.{{ configuration.module }}.{{ configuration.javaName }}Service;
import com.example.studyllm.vo.base.PageResultVO;
import com.example.studyllm.vo.base.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author kw
 * @since {{configuration.date}}
 */
@RestController
@RequestMapping("/{{ configuration.lowerTableName }}")
public class {{ configuration.javaName }}Controller {

    @Resource
    private {{ configuration.javaName }}Service {{ configuration.lowerTableName }}Service;

    /**
     * 通过id查询
     */
    @GetMapping("/{id}")
    public Result<{{configuration.javaName}}> getById(@PathVariable(value = "id") Integer id) {
        return Result.success({{ configuration.lowerTableName }}Service.getById(id));
    }

    /**
     * 新增
     */
    @PostMapping("/")
    public Result save(@RequestBody {{configuration.javaName}} {{ configuration.lowerTableName }}) {
        return Result.success({{ configuration.lowerTableName }}Service.add{{ configuration.javaName }}({{ configuration.lowerTableName }}));
    }

    /**
     * 通过id删除
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") String ids) {
        {{ configuration.lowerTableName }}Service.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/")
    public Result updateById(@RequestBody {{configuration.javaName}} {{ configuration.lowerTableName }}) {
        return Result.success({{ configuration.lowerTableName }}Service.update{{ configuration.javaName }}ById({{ configuration.lowerTableName }}));
    }

    /**
     * 分页查询
     */
    @GetMapping("/")
    public Result<PageResultVO<{{configuration.javaName}}>> page({{configuration.javaName}} {{ configuration.lowerTableName }}) {
        return Result.success({{ configuration.lowerTableName }}Service.getPage({{ configuration.lowerTableName }}));
    }

}
